//////////////////////////////////////////////////////////////////////////
//	Name: CDXLights.h
//	Purpose: Will Create Lights!!
//	Created: October 24, 2009 - Christian Sassi
//////////////////////////////////////////////////////////////////////////

#include "CDXLights.h"
#include "CDXRenderWin32.h"

CDXLights CDXLights::m_instance;

D3DLIGHT9 CDXLights::CreatePointLight(const vec3f &vPos)
{

	// Fill in a light structure defining our light
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof(D3DLIGHT9) );
	light.Type = D3DLIGHT_POINT;
	light.Diffuse.r = 1.0f;
	light.Diffuse.g = 1.0f;
	light.Diffuse.b = 1.0f;
	light.Diffuse.a = 1.0f;

	// Point lights have no direction but do have a position
	D3DVECTOR pos;
	pos.x = vPos.x;
	pos.y = vPos.y;
	pos.z = vPos.z;

	light.Position = pos;

	light.Attenuation0 = 0.1f;
	light.Range = 200.0f;

	//CDXRenderWin32::GetInstance()->GetDevice()->SetLight( 0, &light );

	return light;

	//////////////////////////////////////////////////////////////////////////
	//HOW TO USE THE FUNCTION FOR LIGHTS.
	//////////////////////////////////////////////////////////////////////////
	//SetLights( 1, &light );
	//TurnLightsOn( 1, TRUE );
	//////////////////////////////////////////////////////////////////////////

}

D3DLIGHT9 CDXLights::CreateSpotLight(const vec3f &vPos,const vec3f &vDir)
{

	// Fill in a light structure defining our light
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof(D3DLIGHT9) );
	light.Type       = D3DLIGHT_SPOT;
	light.Diffuse.r = 1.0f;
	light.Diffuse.g = 1.0f;
	light.Diffuse.b = 1.0f;
	light.Diffuse.a = 1.0f;

	// Spot lights have direction and a position

	D3DVECTOR pos;
	pos.x = vPos.x;
	pos.y = vPos.y;
	pos.z = vPos.z;

	light.Position = pos;

	D3DVECTOR dir;
	dir.x = vDir.x;
	dir.y = vDir.y;
	dir.z = vDir.z;

	light.Direction = dir;

	light.Range = 1.0f;
	light.Theta = 0.5f;
	light.Phi = 1.0f;
	light.Falloff = 1.0f;
	light.Attenuation0 = 1.0f;

	return light;

}

D3DLIGHT9 CDXLights::CreateDirectionalLight()
{

	// Fill in a light structure defining our light
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof(D3DLIGHT9) );
	light.Type = D3DLIGHT_DIRECTIONAL;
	light.Diffuse.r = 1.0f;
	light.Diffuse.g = 1.0f;
	light.Diffuse.b = 1.0f;
	light.Diffuse.a = 1.0f;
	light.Range = 1000.0f;

	// Create a direction for our light - it must be normalized 
	vec3f vecDir;
	vecDir = vec3f(0.0f,-0.3f,0.5f);

	vecDir.normalize();

	light.Direction.x = vecDir.x;
	light.Direction.y = vecDir.y;
	light.Direction.z = vecDir.z;

	return light;
}